package com.lfnyxy.service.imp;

import com.lfnyxy.dao.NewsDao;
import com.lfnyxy.entity.NewsEntity;
import com.lfnyxy.query.NewsQuery;
import com.lfnyxy.service.NewsService;
import com.lfnyxy.vo.NewsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsServiceImp implements NewsService {
    @Autowired
    public NewsDao newsDao;

    public int CreateItem(NewsEntity entity) {
        if (entity != null) {
            return newsDao.CreateItem(entity);
        } else {
            return 0;
        }
    }

    public int UpdateItem(NewsEntity entity) {
        if (entity != null) {
            return newsDao.UpdateItem(entity);
        } else {
            return 0;
        }
    }

    public List <NewsVo> QueryPageList(NewsQuery query) {
        int count = newsDao.QueryPageListCount(query);
        query.setTotal(count);
            return newsDao.QueryPageList(query);
    }

    public List <NewsEntity> QueryAll() {
        return newsDao.QueryAll();
    }

    public NewsEntity QueryItem(int Id) {
        if (Id > 0) {
            return newsDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return newsDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    private boolean CheckIsExist(NewsEntity entity) {
        if (entity != null) {
            return newsDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }
}